package com.dongqi.guardrailData.service.impl;

import com.dongqi.guardrailData.dto.GuardrailBoardDTO;
import com.dongqi.guardrailData.entity.GuardrailBoardEntity;
import com.dongqi.guardrailData.mapper.SceneGuardrailBoardMapper;
import com.dongqi.guardrailData.service.GuardrailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
@Transactional
public class GuardrailServiceImpl implements GuardrailService {
    @Autowired
    private SceneGuardrailBoardMapper sceneGuardrailBoardMapper;


    @Override
    public Map<String, Object> queryAll() {
        HashMap<String, Object> map = new HashMap<>();
        List<GuardrailBoardEntity> standardEntities = sceneGuardrailBoardMapper.selectStandard(null);
        List<GuardrailBoardEntity> notStandardEntities = sceneGuardrailBoardMapper.selectNotStandard(null);
        List<GuardrailBoardDTO> standardList = new ArrayList<>();
        List<GuardrailBoardDTO> notStandardList = new ArrayList<>();
        if (standardEntities.size() > 0) {
            for (GuardrailBoardEntity standardEntity : standardEntities) {
                GuardrailBoardDTO guardrailBoardDTO = new GuardrailBoardDTO();
                BeanUtils.copyProperties(standardEntity, guardrailBoardDTO);
                standardList.add(guardrailBoardDTO);
            }
        }
        if (notStandardEntities.size() > 0) {
            for (GuardrailBoardEntity notStandardEntity : notStandardEntities) {
                GuardrailBoardDTO guardrailBoardDTO = new GuardrailBoardDTO();
                BeanUtils.copyProperties(notStandardEntity, guardrailBoardDTO);
                notStandardList.add(guardrailBoardDTO);
            }

        }
        map.put("standard", standardList);
        map.put("notStandard", notStandardList);
        return map;
    }

}
